//
//  GMLoginViewModel.m
//  zbomc
//
//  Created by 雷国敏 on 16/9/28.
//  Copyright © 2016年 N-wei. All rights reserved.
//

#import "GMLoginViewModel.h"

@implementation GMLoginViewModel

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
+ (void)login:(NSDictionary *)prmts success:(void(^)(id respones))success failure:(void(^)(NSError *error))failure
{
	
	NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
	
	
	NSString *serverURLStr;
	LxDBAnyVar([GMDataHandleTool read:GM_ADDRESS]);
	
	//#define AppServerLoginURLString @"http://zbomc.com:8090/wap/json/login/login.action"//正式服务器
	NSString *gm_address = [GMDataHandleTool read:GM_ADDRESS];
	if (gm_address !=nil && gm_address.length > 0) {
		serverURLStr = [NSString stringWithFormat:@"http://%@:8090/wap/json/login/login.action",[GMDataHandleTool read:GM_ADDRESS]];
	}else{
		serverURLStr = AppServerLoginURLString;
	}

	
	//1 参数
	NSString *urlStr = [NSString stringWithFormat:@"%@?phone=%@&password=%@",
						serverURLStr,
						[GMDataHandleTool read:GM_USERNAME],
						[GMDataHandleTool read:GM_PASSWORD]
						];
	LxDBAnyVar(urlStr);
	//1.1 设置用户名和 token
//	[parameters setObject:[GMDataHandleTool read:NEWS_UID] forKey:@"uid"];
//	[parameters setObject:[GMDataHandleTool read:NEWS_ACCESSTOKEN] forKey:@"accesstoken"];
	
	//1.2 如果有其他参数
	if (prmts)
		[parameters addEntriesFromDictionary:prmts];
	
	//2 请求
	[GMAFNetWork GET:urlStr params:parameters success:^(NSURLSessionDataTask *task, id responseObject) {
		if (success) {
			success(responseObject);
		}
	} fail:^(NSURLSessionDataTask *task, NSError *error) {
		failure(error);
	}];
}

@end
